home *** CD-ROM | disk | FTP | other *** search
- /*
-
- SetFileInfo XCMD v1.1
-
- ©1990-1 Apple Computer, Inc.; by Mike Byrne
-
- SetFileInfo is an XCMD to change the type or creator of a file.
-
- Form:
- SetFileInfo <filename>, type | creator, <new value>
-
- # the MPW 3.2 build commands:
- C -b SetFileInfo.c -mbg off
- Link -w -t STAK -c WILD -rt XCMD=607 ∂
- -m ENTRYPOINT ∂
- -sg SetFileInfo ∂
- SetFileInfo.c.o ∂
- "{Libraries}HyperXLib.o" ∂
- "{Libraries}Runtime.o" ∂
- "{Libraries}Interface.o" ∂
- "{CLibraries}StdCLib.o" ∂
- -o "teststack"
- */
-
- #include <Types.h>
- #include <Files.h>
- #include <string.h>
- #include <Memory.h>
- #include <Packages.h>
- #include "HyperXCmd.h"
-
- #define NULL (long) 0
- #define NIL (long) 0
-
- #define kNumParams 3
-
-
- /* prototypes */
- void ErrorBack(XCmdPtr paramPtr, char *message);
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
- void UnlockParams ( XCmdPtr paramPtr, short paramCount );
-
-
-
- pascal void EntryPoint(XCmdPtr paramPtr)
- {
- /* variable declarations */
- OSType newVal;
- short i,j;
- char volName[34];
- char ppathName[301];
- short vRefNum;
- FInfo infoRec;
-
-
- /* move high and lock the parameters. */
- MoveLockParams(paramPtr, paramPtr->paramCount);
-
- /* check for copyright or syntax help request */
- if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
- ErrorBack(paramPtr, "v1.1, ©1990-1 Apple Computer, Inc.; by Mike Byrne");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
- ErrorBack(paramPtr, "SetFileInfo syntax is 'SetFileInfo <filename>, <type | creator>, <new value>'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* not a copyright or help request. */
- /* check for correct number of parameters */
- if (paramPtr->paramCount != kNumParams) {
- ErrorBack(paramPtr, "Error: SetFileInfo syntax is 'SetFileInfo <filename>, <type | creator>, <new value>'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
-
- /* extract the volume name from the handle, copy to a pas string,
- and get the volume reference number of the volume */
- for (i=0; ((*(paramPtr->params[0]))[i] != ':' && (i < 33)); i++)
- { volName[i] = (*(paramPtr->params[0]))[i]; }
- volName[i] = ':';
- volName[i+1] = '\0';
- c2pstr(volName);
- vRefNum = 0;
-
- if (SetVol(volName, vRefNum) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Could not set the default volume");
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
- if (GetVol(&volName, &vRefNum) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Could not find the volume requested.");
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
- /* now, copy the rest of the pathname to the partial pathname and convert it. */
- for (j=i; (j <= strlen((*(paramPtr->params[0]))) && (j < 300)); j++)
- { ppathName[j-i] = (*(paramPtr->params[0]))[j]; }
- c2pstr(ppathName); // toolbox
-
- /* get the old info block for the file */
- if ( GetFInfo(ppathName, vRefNum, &infoRec) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Bad or unknown file name");
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
- /* Move the second parameter into the new value and assign it to whatever is desired */
- BlockMove( (char*)*(paramPtr->params[2]), (Ptr)&newVal, sizeof(OSType) ); // toolbox
- if ( (((char*)*(paramPtr->params[1]))[0] == 't') || (((char*)*(paramPtr->params[1]))[0] == 'T') ) {
- infoRec.fdType = newVal;
- } else {
- infoRec.fdCreator = newVal;
- }
-
- /* set the new information */
- if ( SetFInfo(ppathName, vRefNum, &infoRec) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Bad, locked, or nonexistant file.");
- }
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
-
-
-
-
-
- /* allocate and load up paramPtr->returnValue with a string
- -------------------------------------------------------- */
- void ErrorBack(XCmdPtr paramPtr, char *message)
- {
- Handle mesHnd;
-
- /*
- Allocate space for an error message.
- Copy the string into it.
- Return the handle to HyperCard.
- */
- mesHnd = NewHandle((long)(strlen(message)+1));
- if (mesHnd == nil) return;
- strcpy((char *)*mesHnd,message);
- paramPtr->returnValue = mesHnd;
- }
-
-
-
- /* move high and lock down all parameters
- ----------------------------------------------------------------------- */
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
- {
- short i;
-
- for(i=0; i <= paramCount-1; i++)
- {
- MoveHHi(paramPtr->params[i]);
- HLock(paramPtr->params[i]);
- }
- }
-
-
-
-
- /* unlock all parameter handles in the XCmdBlock
- --------------------------------------------- */
- void UnlockParams ( XCmdPtr paramPtr, short paramCount )
- { short i;
-
- for(i=0; i <= paramCount-1; i++)
- { HUnlock(paramPtr->params[i]);}
- }
-